<template>
	<view>
		<TopNavCustom title="修改手机号"></TopNavCustom>
		<view class="container">
			<view class="change-username">
				<u-input placeholder="请输入手机号" type="number" border="surround" clearable class="username" v-model="phone"></u-input>
				<button type="default" class="btn" @click="saveNickName()">保存</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: "",
			};
		},
		methods: {
			async saveNickName() {
				let newUser = {
					phone: this.phone,
					headerUrl: uni.getStorageSync("headerUrl"),
					userName: uni.getStorageSync('userName'),
					userId: uni.getStorageSync("userId"),
					password: uni.getStorageSync("password"),
					roleId: uni.getStorageSync("roleId"),
					wxId: uni.getStorageSync("wxId"),
				};
				//connet api
				const data = await uni.$H.post("/user/updateUserInfo", newUser, {
					authCode: true,
				});
				if (data.message == "成功") {
					uni.setStorageSync("phone", this.phone);
					uni.$showMsg("修改手机号成功！");
					uni.navigateTo({
						url: "/pages/login/login",
					});
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.change-username {
		display: flex;
		flex-direction: column;

		.username {
			background: #ffffff;
			border: 1rpx solid #ebeef5;
			margin: 30rpx 30rpx 0 30rpx;
			border-radius: 10rpx;
		}

		.btn {
			margin: 120rpx 30rpx 0 30rpx;
			background: linear-gradient(90deg, #e62129 0%, #ba000a 100%);
			box-shadow: 0rpx 5rpx 15rpx 0rpx rgba(0, 0, 0, 0.05);
			border-radius: 44rpx;
			color: #ffffff;
		}
	}
</style>
